﻿using System;
using DAL.Engine.Extention;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using DAL.Engine.Domain;
using DAL.Mongo.Common;

namespace DAL.Mongo.Entity
{
    [TestClass]
    public class EqualsUserTest
    {
        User _user, _other;

        [TestInitialize]
        public void Setup()
        {
            _user = new User
            {
                Id = Guid.Parse("{3835B251-C9D8-4B6A-9EE1-423B7238BE13}"),
                Name = "User"
            };
        }

        //[TestMethod]
        public void ByIdentifierPerfomance()
        {
            var start = DateTime.Now;

            Loop.Start(() => _user.Equals<User, Guid>(_user, EqualsStrategyType.ByIdentifier));

            var execTimeMsec = (DateTime.Now - start).Milliseconds;
        }

        //[TestMethod]
        public void DeepPropComparePerfomance()
        {
            var start = DateTime.Now;

            Loop.Start(() => _user.Equals<User, Guid>(_user, EqualsStrategyType.DeepPropCompare));

            var execTimeMsec = (DateTime.Now - start).Milliseconds;
        }

        [TestMethod]
        public void EqualsWithNull()
        {
            // Act            
            var diff = _user.Equals(null);

            // Assert
            Assert.IsFalse(diff);
        }

        [TestMethod]
        public void EqualsWitTheSameUser()
        {
            var user = _user;

            // Act            
            var diff = _user.Equals(user);

            // Assert
            Assert.IsTrue(diff);
        }

        [TestMethod]
        public void EqualsWitThUser()
        {
            var user1 = new User
            {
                Id = Guid.Parse("{3835B251-C9D8-4B6A-9EE1-423B7238BE13}"),
                Name = "User"
            };
            var user2 = new User
            {
                Id = Guid.Parse("{3835B251-C9D8-4B6A-9EE1-423B7238BE13}"),
                Name = "User"
            };

            // Act            
            var diff1 = _user.Equals(user1);
            var diff2 = user1.Equals(user2);
            var diff3 = _user.Equals(user2);

            // Assert
            Assert.IsTrue(diff1 && diff2 && diff3);
        }

        [TestMethod]
        public void EqualsWithDiffObjectType()
        {
            // Act            
            var diff = _user.Equals(new Object());

            // Assert
            Assert.IsFalse(diff);
        }

        [TestMethod]
        public void EqualsWithOtherUser()
        {
            var diffId = new User
            {
                Id = Guid.Parse("{790178B3-3B38-4E87-B264-62398D21F841}"),
                Name = "New User"
            };
            var diffIdAndName = new User
            {
                Id = Guid.Parse("{790178B3-3B38-4E87-B264-62398D21F841}"),
                Name = "User"
            };
            var diffName = new User
            {
                Id = Guid.Parse("{3835B251-C9D8-4B6A-9EE1-423B7238BE11}"),
                Name = "New User"
            };
            var defaultUser = _user.Equals(new User());

            // Act            
            var diff1 = _user.Equals(diffId);
            var diff2 = _user.Equals(diffIdAndName);
            var diff3 = _user.Equals(diffName);
            var diff4 = _user.Equals(defaultUser);

            // Assert
            Assert.IsFalse(diff1);
            Assert.IsFalse(diff2);
            Assert.IsFalse(diff3);
            Assert.IsFalse(diff4);
        }
    }
}
